Feature: URL and document context attachments#105
Merged
Conversation
There was a problem hiding this comment.
4 issues found across 13 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/codex-claw/src/server/context-attachments.ts">
<violation number="1" location="apps/codex-claw/src/server/context-attachments.ts:149">
P2: Guard decodeURIComponent here. Bad `%` encoding throws and breaks preview. Fallback to raw pathname when decode fails.</violation>
<violation number="2" location="apps/codex-claw/src/server/context-attachments.ts:339">
P1: Add host validation before fetch. Protocol-only check still allows SSRF to internal endpoints. Reject localhost/private network targets (and redirects to them) before downloading preview.</violation>
</file>
<file name="apps/codex-claw/src/screens/chat/components/context-attachment-picker.tsx">
<violation number="1" location="apps/codex-claw/src/screens/chat/components/context-attachment-picker.tsx:180">
P2: Check file size before base64 encode. Big file now gets fully read in browser first. Add early limit guard and fail fast.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| throw new Error('URL context must be a valid http or https URL.') | ||
| } | ||
|
|
||
| if (url.protocol !== 'http:' && url.protocol !== 'https:') { |
There was a problem hiding this comment.
P1: Add host validation before fetch. Protocol-only check still allows SSRF to internal endpoints. Reject localhost/private network targets (and redirects to them) before downloading preview.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/codex-claw/src/server/context-attachments.ts, line 339:
<comment>Add host validation before fetch. Protocol-only check still allows SSRF to internal endpoints. Reject localhost/private network targets (and redirects to them) before downloading preview.</comment>
<file context>
@@ -0,0 +1,587 @@
+ throw new Error('URL context must be a valid http or https URL.')
+ }
+
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
+ throw new Error('URL context only supports http and https links.')
+ }
</file context>
|
|
||
| function titleFromUrl(url: URL) { | ||
| const pathname = url.pathname.split('/').filter(Boolean).pop() ?? '' | ||
| const decoded = pathname ? decodeURIComponent(pathname) : '' |
There was a problem hiding this comment.
P2: Guard decodeURIComponent here. Bad % encoding throws and breaks preview. Fallback to raw pathname when decode fails.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/codex-claw/src/server/context-attachments.ts, line 149:
<comment>Guard decodeURIComponent here. Bad `%` encoding throws and breaks preview. Fallback to raw pathname when decode fails.</comment>
<file context>
@@ -0,0 +1,587 @@
+
+function titleFromUrl(url: URL) {
+ const pathname = url.pathname.split('/').filter(Boolean).pop() ?? ''
+ const decoded = pathname ? decodeURIComponent(pathname) : ''
+ return cleanTitle(decoded.replace(/[-_]+/g, ' ')) || url.hostname
+}
</file context>
| setError(null) | ||
| setDraft(null) | ||
| try { | ||
| const content = await fileToBase64(file) |
There was a problem hiding this comment.
P2: Check file size before base64 encode. Big file now gets fully read in browser first. Add early limit guard and fail fast.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/codex-claw/src/screens/chat/components/context-attachment-picker.tsx, line 180:
<comment>Check file size before base64 encode. Big file now gets fully read in browser first. Add early limit guard and fail fast.</comment>
<file context>
@@ -0,0 +1,354 @@
+ setError(null)
+ setDraft(null)
+ try {
+ const content = await fileToBase64(file)
+ setDraft(
+ await previewContextAttachment({
</file context>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Files
Testing
Risk
Closes #92
Summary by cubic
Adds URL and document context attachments with safe, bounded previews and sends them as prompt context so users can attach web pages or files to a chat. Includes a composer UI to preview and attach up to six items, plus server-side extraction, validation, and tests.
New Features
/api/context-previewto preview URL or document context.contextAttachments./api/sendparses reviewed attachments and builds a prompt block via server utilities, merged with repository context when present.Bug Fixes
Written for commit 8ac096f. Summary will update on new commits.